package com.baor.controller;

import com.baor.dao.CustomerDao;
import com.baor.domain.CustomerVO;
import com.baor.service.TeamService;
import com.baor.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.Random;

@RestController
@RequestMapping(value = "/team")
public class TeamController {
    @Autowired
    private TeamService teamService;

    @PostMapping("/teamList")
    public R getAllTeams(@RequestBody Map<String, Object> params) {
        // 从params中获取参数，兼容null情况
        String nickname = params.getOrDefault("nickname", "").toString().trim();
        String phone = params.getOrDefault("phone", "").toString().trim();


        try {
            List<Map<String, Object>> teams = teamService.getAllTeamsWithMembers(nickname, phone);
            return R.ok(teams);
        } catch (Exception e) {

            return R.er("获取团队列表失败");
        }
    }
    @PostMapping(value = "/updateTeam")
    private R updateTeam(@RequestBody Map<String, Object> params) {
        int row = this.teamService.updateTeam(params);
        return row > 0 ? R.ok("更换成功") : R.er("更换失败");
    }
    @PostMapping(value = "/addHolder")
    private R addHolder(@RequestBody Map<String, Object> params) {
        int row = this.teamService.addHolder(params);
        return row > 0 ? R.ok("更换成功") : R.er("更换失败");
    }
    //绑定设备
    @PostMapping(value = "/bind")
    public  R bind(@RequestBody Map<String, Object> params) {
        int row = this.teamService.bind(params);
        return R.ok(row);
    }
}
